package week07.Mid;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class PlaneFactory {
        private static Properties prop = new Properties();

    static {
        try {
            prop.load(new FileInputStream("src/week07/Mid/plane.properties"));
        } catch (IOException e) {
            System.out.println("读取配置文件失败！");
            e.printStackTrace();
        }
    }

    public static PlaneInAirPort createfly(String planename) {
        Plane plane = createPlane(planename);
        return new PlaneInAirPort(new PlaneProxy(plane));
    }

    private static Plane createPlane(String planename) {

        String className = prop.getProperty(planename);
        Plane plane = null;
        try {
            Class planeClass = Class.forName(className);
            plane = (Plane) planeClass.newInstance();
        } catch (Exception e) {
            System.out.println("实例化失败！");
            e.printStackTrace();
        }
        return plane;

    }
}
